package com.example.yeujian5.yuejian5.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.yeujian5.yuejian5.Listenner.UserCollectListener;
import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.adapter.UserCollectListAdapter;
import com.example.yeujian5.yuejian5.bean.UserCollect;
import com.example.yeujian5.yuejian5.model.UserModel;

import java.util.List;

public class UserCollectActivity extends AppCompatActivity {

    private List<UserCollect> list;
    private RecyclerView recyclerView;
    private List<UserCollect> info;
    private String userid;
    private String user_photo;
    private String user_name;
    private ImageView user_pic;
    private Context context;
    private ImageView collectlist_return;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_collect);
        initViews();
        initEvents();
        getUserId();
        UserCollectList();
    }

    private void initViews(){
        recyclerView = (RecyclerView) findViewById(R.id.user_collect_rv);
        collectlist_return= (ImageView) findViewById(R.id.user_collect_back);
    }

    private void initEvents(){
        collectlist_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        context= UserCollectActivity.this;
    }

    private void UserCollectList() {
        UserModel userModel = new UserModel();
        userModel.getcollect(userid,usercollectListener);
    }

    UserCollectListener usercollectListener=new UserCollectListener() {
        @Override
        public void onResponse(List<UserCollect> stringBean) {
            info = stringBean;
            list = info;
            LinearLayoutManager manager=new LinearLayoutManager(context);
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(manager);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
            recyclerView.setAdapter(new UserCollectListAdapter(UserCollectActivity.this,list,userid));
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(UserCollectActivity.this, "获取失败", Toast.LENGTH_SHORT).show();
        }
    };

    private void getUserId(){
        userid = getApplication().getSharedPreferences("Userid", Context.MODE_PRIVATE).getString("user_id", String.valueOf(0));
        Log.v("collect获取用户id", String.valueOf(userid));
    }
}
